local skel = fk.CreateSkill {
  name = "emo__heli",
}

Fk:loadTranslationTable{
  ["emo__heli"] = "鹤唳",
  [":emo__heli"] = "你的回合内限一次，当你使用一张基本牌或普通锦囊牌时，你可以令之失效并执行两项：1.卜算2并摸两张牌；2.本回合使用牌无距离和次数限制；3.回复1点体力且本回合手牌上限无限；4.令一名其他角色交给你一张手牌且你下一张伤害牌无法响应。",

  ["#emo__heli-ask"] = "鹤唳：你可以令%arg失效，执行两项",
  ["emo__heli_draw"] = "卜算2并摸两张牌",
  ["emo__heli_limit"] = "本回合用牌无距离/次数限制",
  ["emo__heli_recover"] = "回复1点体力,本回合手牌上限无限",
  ["emo__heli_give"] = "令其他角色给你一张牌,你下张伤害牌无法响应",
  ["#emo__heli-choose"] = "鹤唳：令一名其他角色交给你一张手牌",
  ["#emo__heli-give"] = "鹤唳：交给 %src 一张手牌",
  ["@@emo__heli_damage"] = "鹤唳 无法响应",
  ["@@emo__heli_limit-turn"] = "鹤唳 牌无限制",
}

skel:addEffect(fk.CardUsing, {
  anim_type = "control",
  times = function (_, player)
    return 1 - player:usedSkillTimes(skel.name, Player.HistoryTurn)
  end,
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(skel.name) and target == player and player.phase ~= Player.NotActive
    and player:usedSkillTimes(skel.name, Player.HistoryTurn) < 1
    and (data.card.type == Card.TypeBasic or data.card:isCommonTrick())
  end,
  on_cost = function (self, event, target, player, data)
    return player.room:askToSkillInvoke(player, { skill_name = skel.name, prompt = "#emo__heli-ask:::"..data.card:toLogString() })
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local all_choices = {"emo__heli_draw", "emo__heli_limit", "emo__heli_recover", "emo__heli_give"}
    local choices = room:askToChoices(player, {
      choices = all_choices, min_num = 1, max_num = 2, skill_name = skel.name,
    })
    if table.contains(choices, "emo__heli_limit") then
      room:setPlayerMark(player, "@@emo__heli_limit-turn", 1)
    end
    if table.contains(choices, "emo__heli_draw") then
      room:askToGuanxing(player, { cards = room:getNCards(2) })
      player:drawCards(2, skel.name)
    end
    if table.contains(choices, "emo__heli_recover") then
      if player:isWounded() and not player.dead then
        room:recover({ who = player, num = 1, recoverBy = player, skillName = skel.name })
      end
      room:addPlayerMark(player, MarkEnum.AddMaxCardsInTurn, 999)
    end
    if table.contains(choices, "emo__heli_give") and not player.dead then
      room:setPlayerMark(player, "@@emo__heli_damage", 1)
      local targets = table.filter(room:getOtherPlayers(player), function(p) return not p:isKongcheng() end)
      if #targets > 0 then
        local tos = room:askToChoosePlayers(player, {
          skill_name = skel.name, targets = targets, min_num = 1, max_num = 1, prompt = "#emo__heli-choose"
        })
        if #tos > 0 then
          local to = tos[1]
          local give = room:askToCards(to, {
            min_num = 1, max_num = 1, include_equip = false, skill_name = skel.name, cancelable = false,
            prompt = "#emo__heli-give:"..player.id
          })
          if #give > 0 then
            room:obtainCard(player, give, false, fk.ReasonGive, to, skel.name)
          end
        end
      end
    end
    data.nullifiedTargets = table.simpleClone(room.alive_players)
    data.toCard = nil
  end,
})

skel:addEffect(fk.AfterCardUseDeclared, {
  can_refresh = function (self, event, target, player, data)
    return target == player and player:getMark("@@emo__heli_damage") > 0 and data.card.is_damage_card
  end,
  on_refresh = function (self, event, target, player, data)
    player.room:setPlayerMark(player, "@@emo__heli_damage", 0)
    data.disresponsiveList = table.simpleClone(player.room.players)
  end,
})

skel:addEffect("targetmod", {
  bypass_times = function(self, player, skill, scope, card)
    return player:getMark("@@emo__heli_limit-turn") > 0 and card
  end,
  bypass_distances = function(self, player, skill, card)
    return player:getMark("@@emo__heli_limit-turn") > 0 and card
  end,
})

return skel
